﻿#ifndef JSON_JSON_H_INCLUDED
# define JSON_JSON_H_INCLUDED

#include "fstream"
#include "cocos2d.h"
USING_NS_CC;
using namespace std;

# include "value.h"
# include "reader.h"
# include "writer.h"
# include "features.h"

class JsonManager
{
public:
	static JsonManager* instance()
	{
		static JsonManager inst;
		return &inst;
	}
	~JsonManager()
	{

	}

	void getJsonFromFile(const char* fileName, Json::Value& root )
	{
		Json::Reader reader;
		std::string path = cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName);

		//ifstream file(getFullPath(fileName));
		ifstream file(path.c_str());
		CCAssert(file.is_open(),"file is open fail!");
		if(!reader.parse(file, root, false)) 
		{
			CCAssert(false,"Json::Reader Parse error!");
		}
	}

	//const char* getFullPath(const char* path)
	//{
	//	return cocos2d::CCFileUtils::sharedFileUtils()->fullPathFromRelativeFile(path,path);
	//}

private:
	JsonManager()
	{

	}

};




#endif // JSON_JSON_H_INCLUDED
